<template>
  <div id="root">
    <Dialog/>
    <Table/>
    <el-button type="info" @click="showVnode"></el-button>
    <div class="todo-container">
      <div class="todo-wrap">
        <MyHeader :addTodo="addTodo"/>
        <MyList
            :checkTodo="checkTodo"
            :deleteTodo="deleteTodo"
            :todos="todos"
        />
        <MyFooter
            :checkAllTodo="checkAllTodo"
            :clearAllTodo="clearAllTodo"
            :todos="todos"
        />
      </div>
    </div>
  </div>
</template>

<script>
import MyHeader from "./components/todoList/MyHeader.vue";
import MyList from "./components/todoList/MyList.vue";
import MyFooter from "./components/todoList/MyFooter.vue";
import Table from "@/components/table/table";
import Dialog from "@/components/eleui/dialog";

// websocket 测试 |https://cloud.tencent.com/developer/article/1425545
// import Ws from "@/components/ws/ws";

export default {
  name: "App",
  components: {
    MyHeader, MyList, MyFooter, Table, Dialog
  }
  ,
  data() {
    return {
      //由于todos是MyHeader组件和MyFooter组件都在使用，所以放在App中（状态提升）
      todos: [
        {id: "001", title: "抽烟", done: true},
        {id: "002", title: "喝酒", done: false},
        {id: "003", title: "开车", done: true},
      ],
    };
  }
  ,
  methods: {
    showVnode() {
      const h = this.$createElement;
      this.$notify({
        title: '标题名称',
        message: h('i', {style: 'color: teal'}, '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案')
      });
    }
    ,
    //添加一个todo
    addTodo(todoObj) {
      this.todos.unshift(todoObj);
    }
    ,
    //勾选or取消勾选一个todo
    checkTodo(id) {
      this.todos.forEach((todo) => {
        if (todo.id === id) todo.done = !todo.done;
      });
    }
    ,
    //删除一个todo
    deleteTodo(id) {
      this.todos = this.todos.filter((todo) => todo.id !== id);
    }
    ,
    //全选or取消全选
    checkAllTodo(done) {
      this.todos.forEach((todo) => {
        todo.done = done;
      });
    }
    ,
    //清除所有已经完成的todo
    clearAllTodo() {
      this.todos = this.todos.filter((todo) => {
        return !todo.done;
      });
    }
    ,
  }
  ,
}
;
</script>

<style>
/* 注释 */
</style>
